home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 22.7 KB | 753 lines | [TEXT/CWIE] |
- //----------------------------------------------------------------------------------------
- // UODPartView.cp
- // Copyright © 1994-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #if qContainer
-
- #ifndef __UODPARTVIEW__
- #include "UODPartView.h"
- #endif
-
- #ifndef __UINSERTPARTCOMMAND__
- #include "UInsertPartCommand.h"
- #endif
-
- #ifndef __UODPARTVIEWCOMMANDS__
- #include "UODPartViewCommands.h"
- #endif
-
- // MacApp
-
- #ifndef __UCOREGLOBALS__
- #include "UCoreGlobals.h"
- #endif
-
- #ifndef __UFILEBASEDDOCUMENT__
- #include "UFileBasedDocument.h"
- #endif
-
- #ifndef __ULISTITERATOR__
- #include "UListIterator.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UVIEW__
- #include "UView.h"
- #endif
-
- //only temporary!!!•••
- const CommandNumber cInsertPart = 6661;
- const CommandNumber cCopyODPart = 6662;
- const CommandNumber cCutODPart = 6663;
- const CommandNumber cPasteODPart = 6664;
-
-
- //========================================================================================
- // CLASS TODPartView
- //========================================================================================
- #undef Inherited
- #define Inherited TView
-
- #pragma segment ASelCommand
- MA_DEFINE_CLASS_M1(TODPartView, Inherited);
-
- //----------------------------------------------------------------------------------------
- // Constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TODPartView::TODPartView()
- : fSizePartToView(TRUE),
- fCachedOrigin(0,0),
- fFrameRef(NULL),
- fHasPart(FALSE)
-
- {
- }
-
- //----------------------------------------------------------------------------------------
- // Destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TODPartView::~TODPartView()
- {
- fContainerDocument->DeleteODPartView(this);
- // ••• What do we need to do about the fFrameRef here?
- }
-
- //----------------------------------------------------------------------------------------
- // TODPartView::IODPartShape
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TODPartView::IODPartView(TDocument* itsDocument,
- TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- CAFrameRef frameRef)
- {
- this->IView(itsDocument,itsSuperView,itsLocation,itsSize,itsHSizeDet,itsVSizeDet);
-
- fContainerDocument = MA_DYNAMIC_CAST(TFileBasedDocument,itsDocument);
-
- if (fContainerDocument)
- {
- fContainerDocument->AddODPartView(this);
-
- if(fHasPart)
- {
- //Commmand knows about the frameRef
- fFrameRef = frameRef;
- fCachedOrigin = itsLocation;
-
- CADocumentRef containerDoc = itsDocument->GetContainer();
- RgnHandle frameRgn = CAGetFrameRgn(containerDoc, frameRef);
- CRect theFrameRect((**frameRgn).rgnBBox);
-
- fSize = theFrameRect.GetSize();
- DisposeRgn(frameRgn);
- }
- }
- else
- {
- DebugStr("\pAttempting to Initialize a ODPartView with a non file-based document.");
- Failure(minErr, 0);
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // TODPartView::DoPostCreate:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TODPartView::DoPostCreate(TDocument* itsDocument)
- {
- TView::DoPostCreate(itsDocument);
-
- fContainerDocument = MA_DYNAMIC_CAST(TFileBasedDocument,itsDocument);
- if(fContainerDocument)
- fContainerDocument->AddODPartView(this);
- else
- {
- DebugStr("\pAttempting to create a ODPartView with a non file-based document.");
- Failure(minErr, 0);
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // TODPartView::ReadFrom
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
-
- void TODPartView::ReadFrom(TStream* aStream)
- {
- TView::ReadFrom (aStream);
- }
-
- //----------------------------------------------------------------------------------------
- // TODPartView::WriteTo
- //----------------------------------------------------------------------------------------
- #pragma segment AWriteFile
-
- void TODPartView::WriteTo(TStream* aStream)
- {
- TView::WriteTo (aStream);
- }
-
- //----------------------------------------------------------------------------------------
- // TODPartView::Draw
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TODPartView::Draw(const VRect& area)
- {
- TView::Draw(area);
-
- if(fHasPart)
- {
- CADocumentRef containerDoc = fContainerDocument->GetContainer();
- CAVisFrame visFrame = CAGetVisFrame(containerDoc, fFrameRef);
-
- if (visFrame)
- {
- CADrawFrame(visFrame, NULL); // A region ought to be passed here in order to
- } // prevent redraw flickering.
-
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // TODPartView::GetFrameRef
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- CAFrameRef TODPartView::GetFrameRef() const
- {
- return fFrameRef;
- }
-
- //----------------------------------------------------------------------------------------
- // TODPartView::SetFrameRef
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- void TODPartView::SetFrameRef(CAFrameRef newFrameRef)
- {
- fFrameRef = newFrameRef;
- }
-
-
- //----------------------------------------------------------------------------------------
- // TODPartView::AquirePartFromFile
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- void TODPartView::AquirePartFromFile(FSSpec thePartFile)
- {
- CADocumentRef sourceDoc = CAOpenDocument(&thePartFile, NULL, 0, 0);
-
- this->AquirePartFromDocument(sourceDoc);
-
- CACloseDocument(sourceDoc);
- }
-
- //----------------------------------------------------------------------------------------
- // TODPartView::AquirePartFromDocument
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- void TODPartView::AquirePartFromDocument(CADocumentRef sourceDocument)
- {
- CATransform extTransform;
-
- CADocumentRef destDocument = fContainerDocument->GetContainer();
- CACloneKey cloneKey = CABeginClone(sourceDocument, destDocument, kCACloneAll);
- CAFrameRef newFrameRef = CACloneFrameRef(NULL, sourceDocument, destDocument, TRUE, cloneKey);
- CAEndClone(sourceDocument, destDocument, cloneKey);
-
- this->SetFrameRef(newFrameRef);
-
- VRect frameRect(GetFrame());
- CRect theCRectFrame(frameRect.ToRect());
-
- CAVisFrame visFrame = CAGetVisFrame(destDocument, fFrameRef);
-
- CAMoveTransformTo(&extTransform, theCRectFrame[topLeft]);
- CAMakeVisFrame(destDocument,fFrameRef, NULL, &extTransform, NULL);
-
- //CAVisFrame visFrame = CAGetVisFrame(destDocument, fFrameRef);
- //CADrawFrame (visFrame,NULL);
- CASetSelected (visFrame, TRUE); // Set the facet as selected, in place
-
- fHasPart = TRUE;
- }
-
-
- //----------------------------------------------------------------------------------------
- // TODPartView::SizePartToView
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- void TODPartView::SizePartToView()
- {
- CADocumentRef destDocument = fContainerDocument->GetContainer();
-
- //First, Adjust the Frame
- RgnHandle newRgnForFrame = NewRgn();
-
- VRect theVisibleExtent(GetVisibleExtent());
- CRect theCRectVisibleExtent = theVisibleExtent.ToRect();
-
- RectRgn(newRgnForFrame,theCRectVisibleExtent);
- CASetFrameRgn(destDocument,this->fFrameRef,newRgnForFrame);
-
- //Second, Update the Facet (visFrame)
- CAVisFrame theVisFrame = CAGetVisFrame(destDocument,this->fFrameRef);
- if(theVisFrame)
- {
- RgnHandle newRgnForFacet = CAGetFrameRgn(destDocument,this->fFrameRef);
- CAAdjustVisFrame(theVisFrame,newRgnForFacet,NULL);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TODPartView::SizeViewToPart
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- void TODPartView::SizeViewToPart()
- {
- //there is an adorner bug that makes this
- //look like it is not totally working, but it is.
-
- if(fHasPart)
- {
- CADocumentRef containerDoc = fContainerDocument->GetContainer();
- RgnHandle frameRgn = CAGetFrameRgn(containerDoc, fFrameRef);
- CRect theFrameRect((**frameRgn).rgnBBox);
-
- fSize = theFrameRect.GetSize();
- this->ForceRedraw();
- DisposeRgn(frameRgn);
- }
- }
-
-
- //----------------------------------------------------------------------------------------
- // TODPartView::NegotiateFrameChange(RgnHandle theRgn)
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- Boolean TODPartView::NegotiateFrameChange(RgnHandle theRgn)
- {
-
- //•••NOTE!! This is not working, just a place holder with some ideas on how it might work.
-
-
- Boolean grantedRequest = FALSE;
-
- if(!fRejectFrameChangeRequests || !(fSizeDeterminer[vSel] == sizeFixed &&
- fSizeDeterminer[hSel] == sizeFixed) || !fSizePartToView)
- {
- if(fSizeDeterminer[vSel] == sizeVariable && fSizeDeterminer[hSel] == sizeVariable)
- {
- //we are size variable, so resize to the size of the frame
- grantedRequest = TRUE;
- this->SetFrame((**theRgn).rgnBBox, TRUE);
- }
- else
- if(fSizeDeterminer[vSel] == sizeVariable && !(fSizeDeterminer[hSel] == sizeVariable))
- {
- grantedRequest = FALSE;
- //adjust the region
- //this->SetFrame((**rgn).BBox, TRUE)
- }
- else
- if(!(fSizeDeterminer[vSel] == sizeVariable) && fSizeDeterminer[hSel] == sizeVariable)
- {
- grantedRequest = FALSE;
- //adjust the region
- //this->SetFrame((**rgn).BBox, TRUE)
- }
- }
-
- if(grantedRequest == FALSE)
- {
- RgnHandle newRgnForFrame = NewRgn();
-
- VRect theVisibleExtent = this->GetVisibleExtent();
- CRect theCRectVisibleExtent = theVisibleExtent.ToRect();
-
- RectRgn(newRgnForFrame,theCRectVisibleExtent);
-
- theRgn = newRgnForFrame;
- }
-
- return grantedRequest;
- }
-
-
- //----------------------------------------------------------------------------------------
- // TODPartView::RemovePart()
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- void TODPartView::RemovePart()
- {
- CADocumentRef containerDoc = fContainerDocument->GetContainer();
- CAFrameRef frameRef = this->GetFrameRef();
- RgnHandle oldFrameRegion = CAGetFrameRgn(containerDoc,frameRef);
-
- CAVisFrame oldVisFrame = CAGetVisFrame(containerDoc, frameRef);
- CARemoveVisFrame(oldVisFrame);
- CARemoveFrameRef(containerDoc,frameRef);
-
- this->InvalidateRegion(oldFrameRegion);
-
- this->fHasPart = FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TODPartView::HasPart()
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- Boolean TODPartView::HasPart()
- {
- return fHasPart;
- }
-
- //----------------------------------------------------------------------------------------
- // TODPartView::SetFrame
- //----------------------------------------------------------------------------------------
- #pragma segment AClipboard
-
- void TODPartView::SetFrame(const VRect& newFrame, Boolean invalidate)
- {
- TView::SetFrame(newFrame, invalidate);
-
- if(fSizePartToView)
- this->SizePartToView();
- }
-
- //----------------------------------------------------------------------------------------
- // TODPartView::DoKeyEvent
- //----------------------------------------------------------------------------------------
- void TODPartView::DoKeyEvent(TToolboxEvent* event)// override
- {
-
- Boolean handledCharacter = FALSE;
-
- if (this->IsEnabled() && this->HasPart())
- if (event->fText == chFwdDelete || event->fText == chBackspace)
- {
- this->RemovePart();
- handledCharacter = TRUE;
- }
-
- if (!handledCharacter)
- Inherited::DoKeyEvent(event);
- } // TODPartView::DoKeyEvent
-
-
- //----------------------------------------------------------------------------------------
- // TODPartView::DoSetupMenus
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TODPartView::DoSetupMenus()
- {
- Inherited::DoSetupMenus();
-
- Enable(cInsertPart, TRUE);
-
- Enable(cPaste,TRUE); //•• use CanPaste method
-
- if(fHasPart)
- {
-
- Enable(cODGetPartInfo,TRUE); //<- this should only be enabled if it has a part and the part
- // is not "active", since there is not sence of selection in the
- // view....
- //Enable(cODViewAsWindow,TRUE); //bug in CALib will crash your machine.....enable with warning.
- Enable(cCut,TRUE);
- Enable(cCopy,TRUE);
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // TODPartView::DoMenuCommand
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TODPartView::DoMenuCommand(CommandNumber aCommandNumber)
- {
-
- switch (aCommandNumber)
- {
- case cCopy :
- TCopyODPartCommand* theCopyPartCommand = new TCopyODPartCommand;
- theCopyPartCommand->ICopyODPartCommand(cCopyODPart,this->fContainerDocument, this);
- this->PostCommand(theCopyPartCommand);
- break;
-
- case cCut :
- TCutODPartCommand* theCutPartCommand = new TCutODPartCommand;
- theCutPartCommand->ICutODPartCommand(cCutODPart,this->fContainerDocument, this);
- this->PostCommand(theCutPartCommand);
- break;
-
- case cPaste :
- TPasteODPartCommand* thePasteCommand = new TPasteODPartCommand;
- thePasteCommand->IPasteODPartCommand(cPasteODPart,this->fContainerDocument, this);
- this->PostCommand(thePasteCommand);
- break;
-
- case cInsertPart:
- {
- TInsertPartCommand* command = new TInsertPartCommand;
- if (command->IInsertPartCommand(aCommandNumber, this->fContainerDocument, this))
- this->PostCommand(command);
- else
- command = (TInsertPartCommand*) FreeIfObject(command);
- }
- break;
-
- case cODGetPartInfo :
- //•••Bug in CALib
- CADocumentRef containerDoc = fContainerDocument->GetContainer();
- CAVisFrame visFrame = CAGetVisFrame(containerDoc, this->fFrameRef);
- CAShowPartFrameInfo(containerDoc, visFrame);
- FailOSErr(CAError());
- break;
-
- case cODViewAsWindow :
- //•••Bug in CALib
- //CAViewFrameInWindow(containerDoc,frameRef);
- break;
-
- default:
- Inherited::DoMenuCommand(aCommandNumber);
- break;
- }
-
- } // TODPartView::DoMenuCommand
-
- #if qDrag
- //----------------------------------------------------------------------------------------
- // TODPartView::WillAcceptDrop
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- Boolean TODPartView::WillAcceptDrop(CDragItemIterator& dragItemIterator)
- {
- Boolean returnValue = FALSE;
-
- //we only accept one part per view
- if (TDragDropSession::fgDragDropSession->GetItemCount() != 1)
- return FALSE;
-
- TDragItem *firstItem = dragItemIterator.FirstDragItem();
-
- if(firstItem->FlavorExists('hfs ')) //flavorTypeHFS
- {
- Handle dataHandle;
- OSErr theErr = noErr;
- long dataSize = 0;
- HFSFlavor theHFSFlavor;
- //CADocumentRef sourceDoc;
-
- firstItem->FocusOnFlavor('hfs ');
- dataHandle = firstItem->GetDataAsHandle();
-
- BlockMoveData( *dataHandle, &theHFSFlavor, (long)sizeof(HFSFlavor) );
-
- if (theHFSFlavor.fileCreator == kODShellSignature)
- returnValue = TRUE;
- else
- returnValue = FALSE;
-
- }
- else
- returnValue = FALSE;
-
- return returnValue;
-
- } // TODPartView::WillAcceptDrop
-
- //----------------------------------------------------------------------------------------
- // TODPartView::DoMakeDragDropCommand
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TCommand* TODPartView::DoMakeDragDropCommand(CommandNumber itsCommandNumber,
- CDragItemIterator& dragItemIterator)
- {
- TCommand *returnCommand = NULL;
- TCommandHandler *itsContext = this->GetContext(itsCommandNumber);
-
- switch(itsCommandNumber)
- {
- case cDrag:
- break;
-
- case cDrop:
- {
- OSErr theErr = noErr;
- long dataSize = 0;
- HFSFlavor theHFSFlavor;
-
- TDragItem *firstItem = dragItemIterator.FirstDragItem();
- firstItem->FocusOnFlavor('hfs ');
- Handle dataHandle = firstItem->GetDataAsHandle();
- BlockMoveData( *dataHandle, &theHFSFlavor, (long)sizeof(HFSFlavor) );
-
-
-
- TODPartViewCommand *dropCommand = new TODPartViewCommand;
- dropCommand->IODPartViewCommand(theHFSFlavor.fileSpec, this, itsCommandNumber,
- itsContext, kCantUndo, kDoesNotCauseChange,
- itsContext);
- returnCommand = dropCommand;
- }
- break;
-
- case cDragMove:
- break;
-
- default:
- returnCommand = Inherited::DoMakeDragDropCommand(itsCommandNumber, dragItemIterator);
- break;
- }
-
- return returnCommand;
- } // TODPartView::DoMakeDragDropCommand
-
- #endif
-
- //----------------------------------------------------------------------------------------
- // InitUODPartView:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgInit
-
- void InitUODPartView()
- {
- MA_REGISTER_CLASS(TODPartView);
- }
-
- //========================================================================================
- // CLASS TODPartViewCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment MADragNonRes
- MA_DEFINE_CLASS_M1(TODPartViewCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TODPartViewCommand::TODPartViewCommand
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TODPartViewCommand::TODPartViewCommand()
- {
- fODPartView = NULL;
- } // TODPartViewCommand::TODPartViewCommand
-
- //----------------------------------------------------------------------------------------
- // TODPartViewCommand::IODPartViewCommand
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TODPartViewCommand::IODPartViewCommand(FSSpec theFileSpec,
- TODPartView* thePartView,
- CommandNumber itsCommandNumber,
- TCommandHandler* itsContext,
- Boolean canUndo,
- Boolean causesChange,
- TObject* objectToNotify)
- {
- fFileSpec = theFileSpec;
- fODPartView = thePartView;
- this->ICommand(itsCommandNumber, itsContext, canUndo, causesChange, objectToNotify);
- } // TODPartViewCommand::IPictureCommand
-
- //----------------------------------------------------------------------------------------
- // TODPartViewCommand::~TODPartViewCommand
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TODPartViewCommand::~TODPartViewCommand()
- {
- } // TODPartViewCommand::~TODPartViewCommand
-
- //----------------------------------------------------------------------------------------
- // TODPartViewCommand::DoIt
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TODPartViewCommand::DoIt()
- {
- fODPartView->AquirePartFromFile(fFileSpec);
- } // TODPartViewCommand::DoIt
-
-
- //========================================================================================
- // CLASS CODPartViewIterator
- //========================================================================================
- #undef Inherited
- #define Inherited CObjectIterator
-
- /*
- //----------------------------------------------------------------------------------------
- // CODPartViewIterator::CODPartViewIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- CODPartViewIterator::CODPartViewIterator(const TFileBasedDocument* theFBDocument,
- ArrayIndex itsLowBound,
- ArrayIndex itsHighBound,
- Boolean itsForward)
- {
- CObjectIterator(theFBDocument ? theFBDocument->fODPartViewList : NULL, itsLowBound, itsHighBound,itsForward);
- } // CODPartViewIterator::CODPartViewIterator
- */
-
- //----------------------------------------------------------------------------------------
- // CODPartViewIterator::CODPartViewIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
-
- CODPartViewIterator::CODPartViewIterator(TFileBasedDocument* theFBDocument,
- Boolean itsForward) :
- CObjectIterator(theFBDocument ? theFBDocument->fODPartViewList : NULL, itsForward)
- {
- } // CCADocumentIterator::CDocumentIterator
-
- //----------------------------------------------------------------------------------------
- // CODPartViewIterator::CODPartViewIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
-
- CODPartViewIterator::CODPartViewIterator(TFileBasedDocument* theFBDocument) :
- CObjectIterator(theFBDocument ? theFBDocument->fODPartViewList : NULL, kIterateForward)
- {
- } // CODPartViewIterator::CODPartViewIterator
-
- //----------------------------------------------------------------------------------------
- // CODPartViewIterator::~CODPartViewIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
-
- CODPartViewIterator::~CODPartViewIterator()
- {
- } // CODPartViewIterator::~CODPartViewIterator
-
- //----------------------------------------------------------------------------------------
- // CODPartViewIterator::CurrentODPartView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
-
- TODPartView* CODPartViewIterator::CurrentODPartView()
- {
- return (TODPartView*)this->CurrentObject();
- } // CODPartViewIterator::CurrentODPartView
-
- //----------------------------------------------------------------------------------------
- // CCADocumentIterator::FirstDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
-
- TODPartView* CODPartViewIterator::FirstODPartView()
- {
- return (TODPartView *)this->FirstObject();
- } // CCADocumentIterator::FirstDocument
-
- //----------------------------------------------------------------------------------------
- // CCADocumentIterator::NextDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
-
- TODPartView* CODPartViewIterator::NextODPartView()
- {
- return (TODPartView *)this->NextObject();
- } // CCADocumentIterator::NextDocument
-
-
- //----------------------------------------------------------------------------------------
- // End of UODPartView.cp
-
- #endif //qContainer
- #pragma segment Inline
-